Skip to content

feat(sql): add native ConnectorX SQL engine support - #12234

Open
GiacomoSaccaggi wants to merge 3 commits into
marimo-team:mainfrom
GiacomoSaccaggi:feat/connectorx-sql-engine
Open

GiacomoSaccaggi wants to merge 3 commits into
marimo-team:mainfrom
GiacomoSaccaggi:feat/connectorx-sql-engine

Conversation

@GiacomoSaccaggi

@GiacomoSaccaggi GiacomoSaccaggi commented Dec 2, 2026 •

Copy link
Copy Markdown

📝 Summary

Relates to #10396.

This PR adds ConnectorX as a first-class SQL engine so users can pass a ConnectorXConnection URI directly to any marimo SQL cell — without wrapping it in a SQLAlchemy engine first.

Motivation

Users already in the Polars ecosystem often connect to databases via polars.read_database_uri(query, cx_uri), which uses ConnectorX under the hood. When migrating to marimo, they had to rewrite those connections as SQLAlchemy engines to use SQL cells. This PR removes that friction: the same URI just works.

The main value over the existing SQLAlchemy path:

  • No Python drivers to install: ConnectorX bundles its connectors in Rust — no psycopg2, no trino-python-client
  • Zero-copy Arrow→Polars: reads directly into Arrow; pl.from_arrow() is zero-copy. Pandas is never imported when output is polars or native
  • Familiar URI format: users of polars.read_database_uri() can reuse the exact same URI string

Usage

from marimo._sql.engines.connectorx import ConnectorXConnection

# PostgreSQL — no psycopg2 needed
conn = ConnectorXConnection("postgresql://user:pass@host:5432/db")

# Trino with TLS (analytics warehouse)
conn = ConnectorXConnection(
    "trino+https://user:pass@trino.example.com:8443/catalog?verify=false"
)

# Amazon Redshift
conn = ConnectorXConnection("redshift://user:pass@host:5439/db")

Then use conn in any SQL cell via the engine dropdown or mo.sql(..., engine=conn).

Explicitly out of scope

  • UI wizard ("Add Database Connection" button): requires frontend changes; proposed as a follow-up once the API direction is confirmed
  • Schema introspection: ConnectorX has no catalog API; the Data Sources panel shows the connection entry but not schemas/tables
  • Write queries: ConnectorX is read-only (SELECT only)

Files changed

File Change
marimo/_dependencies/dependencies.py Register connectorx>=0.4.6 in DependencyManager
marimo/_sql/engines/connectorx.py New: ConnectorXConnection wrapper + ConnectorXEngine
marimo/_sql/get_engines.py Add import + register in SUPPORTED_ENGINES
tests/_sql/test_connectorx.py New: 37 tests
docs/guides/working_with_data/sql.md Add ConnectorX tab, database table entries, library list

Test coverage

pytest tests/_sql/test_connectorx.py -v   → 37 passed, 0 skipped
pytest tests/_sql/ -v                     → 585 passed, 0 regressions
ruff check + ruff format --check          → all clean

Tests cover: dialect detection (13 URI schemes), credential masking, is_compatible rejection of plain strings (SQLAlchemy non-regression), missing-dependency error, Trino URI pass-through with mocked cx.read_sql asserting return_type='arrow' (never 'arrow2'), end-to-end SQLite queries for all output formats (polars, lazy-polars, pandas, native, auto).


👋 First time contributor introduction

I'm Giacomo, a big fan of what the marimo team is building and I want to contribute back with something that comes directly from my own work. I build analytical dashboards on top of Trino data warehouses using Polars, and I'm also a contributor to ConnectorX itself — I fixed Trino URL parameter forwarding (#928) and stopped connection URLs from being incorrectly form-encoded (#933), which is what made trino+https://...?verify=false reliable in connectorx>=0.4.6. When I tried to bring that stack into marimo I hit exactly the friction in #10396: I had working ConnectorX URIs for Trino and had to rewrite everything as SQLAlchemy just to use SQL cells. This PR is my attempt to close that gap.


📋 Pre-Review Checklist

ConnectorX engine selected in a SQL cell

✅ Merge Checklist

  • I have read the contributor guidelines
  • Documentation has been updated (docs/guides/working_with_data/sql.md)
  • Tests have been added (37 tests in tests/_sql/test_connectorx.py)

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@GiacomoSaccaggi
GiacomoSaccaggi force-pushed the feat/connectorx-sql-engine branch from dfbfa81 to 3b2b776 Compare December 2, 2026 15:42
GiacomoSaccaggi and others added 2 commits December 2, 2026 16:45
Relates to marimo-team#10396.

ConnectorX is a Rust-based SQL connector that reads query results
directly into Arrow format, enabling zero-copy conversion to Polars.
This PR adds it as a first-class SQL engine so users can pass a
ConnectorXConnection URI directly to any marimo SQL cell without
wrapping it in a SQLAlchemy engine.

Key design decisions:
- ConnectorXConnection wrapper class (not plain string matching) to
  avoid any risk of hijacking existing SQLAlchemy string variables
- Always uses return_type='arrow' (requires connectorx>=0.4.6, which
  removed the deprecated 'arrow2' return type)
- Zero-copy Arrow->Polars via pl.from_arrow(); pandas not imported
  when output is 'polars' or 'native'
- QueryEngine only (no EngineCatalog): ConnectorX has no introspection
  API; Data Sources panel shows the connection but not schemas/tables
- Credentials masked in repr, display names, and all exception messages

Supported URI schemes: postgresql, mysql, sqlite, trino (+https/+http),
redshift, bigquery, mssql, oracle, clickhouse.

Co-authored-by: Elisa Tedde <79220600+elitedde@users.noreply.github.com>
Co-authored-by: Elisa Tedde <79220600+elitedde@users.noreply.github.com>
@GiacomoSaccaggi
GiacomoSaccaggi force-pushed the feat/connectorx-sql-engine branch 2 times, most recently from e393640 to 5a95848 Compare December 2, 2026 15:46
@GiacomoSaccaggi

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

1 similar comment
@elitedde

elitedde commented Dec 2, 2026

Copy link
Copy Markdown

I have read the CLA Document and I hereby sign the CLA

@GiacomoSaccaggi

Copy link
Copy Markdown
Author

Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.

I have read the CLA Document and I hereby sign the CLA

1 out of 2 committers have signed the CLA.✅ GiacomoSaccaggi❌ @eliteddeYou can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

recheck

@kirangadhave
kirangadhave requested review from Light2Dark and a balanced review from Copilot December 2, 2026 17:58
@kirangadhave kirangadhave added the enhancement New feature or request label Dec 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The TLS example disables certificate verification while sending credentials, exposing users to man-in-the-middle attacks, and incomplete redaction can leak passwords and tokens.

6 open issues
What changed in this PR

Adds ConnectorX as a SQL engine, letting notebooks reuse connection URIs without SQLAlchemy, addressing #10396.

Changes:

  • Registers ConnectorX and adds Arrow-based query execution with configurable output formats.
  • Adds dialect, credential-masking, and query execution tests.
  • Documents installation, usage, supported databases, and limitations.
File Description
tests/​_sql/​test_connectorx.py Tests connection handling and query outputs.
marimo/​_sql/​get_engines.py Registers the engine for discovery.
marimo/​_sql/​engines/​connectorx.py Implements the connection wrapper and execution adapter.
marimo/​_dependencies/​dependencies.py Registers the ConnectorX dependency.
docs/​guides/​working_with_data/​sql.md Documents ConnectorX setup and usage.

Review effort: Balanced

Comment thread docs/guides/working_with_data/sql.md Resolved
Comment thread docs/guides/working_with_data/sql.md Resolved
Comment thread marimo/_sql/engines/connectorx.py Resolved
Comment thread marimo/_sql/engines/connectorx.py Resolved
Comment thread marimo/_sql/engines/connectorx.py Resolved
Comment thread tests/_sql/test_connectorx.py Resolved
- Require pyarrow explicitly before reading Arrow results
- Redact both percent-encoded and URL-decoded password from errors
- Remove verify=false from docs example; add TLS warning admonition
- Add pyarrow to install command in docs
- Add test for URL-encoded password redaction
@elitedde

elitedde commented Dec 3, 2026

Copy link
Copy Markdown

recheck

@GiacomoSaccaggi
GiacomoSaccaggi marked this pull request as ready for review December 3, 2026 08:44

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants